package graph.drawingshapes.shapes
{
	import graph.drawingshapes.RedrawEvent;
	import graph.geometricshapes.GeometricRoundedRectangle;
	import graph.geometricshapes.GeometricRoundedShapeFactory;
	import graph.geometricshapes.IRounded;
	
	public class RoundedRectangleShape extends RectangleShape
	{
		public static const NAME:String = "RoundedRectangleShape";
		public override function get getName():String
		{
			return NAME;
		}
		
		public function RoundedRectangleShape(x:Number=DefaultX, y:Number=DefaultY, width:Number=DefaultWidth, height:Number=DefaultHeight, cornerRadius:Number = 5)
		{
			super(x, y, width, height);
			this.geometricShape = GeometricRoundedShapeFactory.createShape(GeometricRoundedRectangle.NAME, width, height, cornerRadius);
			dispatchEvent(new RedrawEvent());
		}
		
		protected override function draw():void
		{
			if (!(this.geometricShape is IRounded)) return;			
			this.graphics.drawRoundRect(0, 0, width, height,(geometricShape as IRounded).cornerRadius, (geometricShape as IRounded).cornerRadius);
		}
		
		/* public override function set width(value:Number):void
		{
			if (value<0)
			{
				var dx:Number = Math.abs(value)-this.width;
				this.x -= dx;
				super.width = Math.abs(value);
			}
			else
			{
				super.width = value;
			}
		}
		
		public override function set height(value:Number):void
		{
			if (value<0)
			{
				var dy:Number = Math.abs(value)-this.height;
				this.y -= dy;
				super.height = Math.abs(value);
			}
			else
			{
				super.height = value;
			}
		} */
		
	}
}